package mathproblem;
import java.math.BigDecimal;
import java.util.Random;
import java.util.Scanner;

import java.math.BigDecimal;

public class Test2 {
	public static void main(String[] args){
		System.out.println("您已进入测试");
//用户可以决定半径和高的范围
		System.out.println("请输入您想产生的随机数范围：");
		Scanner range=new Scanner(System.in);
		int ran=range.nextInt();
//随机产生立方体类型
		Random random=new Random();
		int type=random.nextInt(3);
//产生半径、高和立方体类型
		int radius=random(ran);
		int high=random(ran);
		System.out.println("请问半径为"+radius+"高为"+high+"的"+typing(type)+"面积为？体积为？");
		
		Define cal=new Define();
//系统得出答案
		double answera=0,answerv=0;
		if(type==0){
			answerv=MyMath.round(cal.cylinderv(radius, high), 2);
			answera=MyMath.round(cal.cylinderv(radius, high), 2);
		}
		else if(type==1){
			answerv=MyMath.round(cal.conev(radius, high), 2);
			answera=MyMath.round(cal.conev(radius, high), 2);
		}
		else if(type==2){
			answerv=MyMath.round(cal.balla(radius), 2);
			answera=MyMath.round(cal.ballv(radius), 2);
		}
//用户输入答案
		double inputa=inputArea();
		double inputv=inputVolume();
//判断用户输入和系统得出的答案是否一致
		if(judgeAnswer(inputa,inputv,answera,answerv)){
			System.out.println("恭喜您，回答正确！");
		}
		else{
			System.out.println("抱歉，您答错了");
		}
	}
//随机产生半径和高
	public static int random(int range){
		Random random=new Random();
		int ran=random.nextInt(range);
		return ran;
	}
//随机产生立方体类型
	public static String typing(int type){
		String typing=null;
		switch(type){
		case 0:
			typing="圆柱体";
			break;
		case 1:
			typing="圆锥体";
			break;
		case 2:
			typing="球";
			break;
		}
		return typing;
	}
//用户输入答案
	public static double inputArea(){
		System.out.println("请输入您计算的面积值（保留两位小数）");
		Scanner input=new Scanner(System.in);
		double inputa=input.nextDouble();
		return inputa;
	}
	public static double inputVolume(){
		System.out.println("请输入您计算的体积值（保留两位小数）");
		Scanner input=new Scanner(System.in);
		double inputv=input.nextDouble();
		return inputv;
	}
//判断用户输入与答案是否一致
	public static boolean judgeAnswer(double inputa,double inputv,double answera,double answerv){
		if(inputa==answera){
			if(inputv==answerv){
				return true;
			}
		}
		return false;
	}
}

